namespace CaltechSoft.Service.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Add_AE_Table : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.AEs",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        PONo = c.String(),
                        AENo = c.String(),
                        AEDate = c.DateTime(nullable: false),
                        PaymentDate = c.DateTime(nullable: false),
                        Total = c.Single(nullable: false),
                        CompanyId = c.Int(nullable: false),
                        Reason = c.String(),
                        LeaderId = c.String(maxLength: 128),
                        AccountingId = c.String(maxLength: 128),
                        AccountingManagerId = c.String(maxLength: 128),
                        ManagerId = c.String(maxLength: 128),
                        CreatedBy = c.String(maxLength: 128),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.AccountingId)
                .ForeignKey("dbo.AspNetUsers", t => t.AccountingManagerId)
                .ForeignKey("dbo.Customers", t => t.CompanyId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.LeaderId)
                .ForeignKey("dbo.AspNetUsers", t => t.ManagerId)
                .ForeignKey("dbo.AspNetUsers", t => t.CreatedBy)
                .Index(t => t.CompanyId)
                .Index(t => t.LeaderId)
                .Index(t => t.AccountingId)
                .Index(t => t.AccountingManagerId)
                .Index(t => t.ManagerId)
                .Index(t => t.CreatedBy);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.AEs", "CreatedBy", "dbo.AspNetUsers");
            DropForeignKey("dbo.AEs", "ManagerId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AEs", "LeaderId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AEs", "CompanyId", "dbo.Customers");
            DropForeignKey("dbo.AEs", "AccountingManagerId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AEs", "AccountingId", "dbo.AspNetUsers");
            DropIndex("dbo.AEs", new[] { "CreatedBy" });
            DropIndex("dbo.AEs", new[] { "ManagerId" });
            DropIndex("dbo.AEs", new[] { "AccountingManagerId" });
            DropIndex("dbo.AEs", new[] { "AccountingId" });
            DropIndex("dbo.AEs", new[] { "LeaderId" });
            DropIndex("dbo.AEs", new[] { "CompanyId" });
            DropTable("dbo.AEs");
        }
    }
}
